<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
/********************
 *@param function:OplusCms 後台首頁
 *@param datetime 2012-01-05
 *@param author solgh
 ********************/
class Index extends Admins_Controller {
  
  private $data=array();

  public function __construct(){
    parent::__construct();
    $this->data['currentPage']='index';
    $this->data['format_time']=$this->settings['default_time'];
	  $this->data['lang'] =$this->lang->language;
  }

  public function index(){
    $endTime = time();
    $startTime = strtotime(date('Y-m-d',time()));
    $where = "add_time > ".$startTime." and add_time <= ".$endTime;
    $sql = "select sum(total) as total from clickrcms_order where ".$where;
    $query = $this->db->query($sql);
    $this->data['orders']=$query->row_array();
    $this->_get_list();
    $this->get_website_totle();//獲取統計數據
    $this->load->view('admins/index_list_view',$this->data);
  }

  //獲取訂單數
  private function _get_list(){
    //總共
    $this->load->model('orders_mdl');
    $this->data['total_order']=$this->orders_mdl->totle_orders();

    //今天
    $today_begin = date("Y-m-d 00:00:00");
    $today_end = date("Y-m-d 23:59:59");
    $today=array(
      'begin_time'=>strtotime($today_begin),
      'end_time'=>strtotime($today_end),
    );
    $this->data['today_order']=$this->orders_mdl->totle_orders($today);

    //昨天
    $yest_begin = date("Y-m-d 00:00:00",strtotime('-1 day'));
    $yest_end = date("Y-m-d 23:59:59",strtotime('-1 day'));
    $yest=array(
      'begin_time'=>strtotime($yest_begin),
      'end_time'=>strtotime($yest_end),
    );
    $this->data['yest_order']=$this->orders_mdl->totle_orders($yest);
  }
  
  //獲取統計數據
  public function get_website_totle(){
    $this->load->helper('count');
    $this->data['website_count']=admin_website_count();
  }
  
  //美圖秀秀
  public function tools(){
    $this->load->view('admins/index_tool_view',$this->data);
  }
  
  //權限不夠
  public function permission(){
    $this->load->view("admins/permission_error_view",$this->data);
  }
}
